<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2021/12/9
 * Time: 11:06
 */
//include_once "../connTools.php";


$conn = new mysqli();
$conn->connect('127.0.0.1','root','root','bank');
if(!empty($conn->connect_error)){
    echo '数据库连接错误:'.$conn->connect_error;
    die;
}
//echo '数据库连接成功<br />';
//connTools::setConn($conn);
$result = $conn->query('select a.RealName,b.CardNo,b.CardPwd from bankcard b join accountinfo a on a.AccountId = b.AccountId');
$username = $_POST["username"];
$password = $_POST["psd"];
$userkey=md5($username.$password);
$fa=false;
while (true){
    $date=$result->fetch_assoc();
    if (empty($date)){
        break;
    }
    if($username==$date['CardNo']&&$password==$date['CardPwd']){
        setcookie('key',$userkey,time()+24*3600,'/');
        session_start();
        $_SESSION[$userkey]=
        [
            'RealName'=>$date['RealName'],
            'CardNo'=>$username,
            'CardPwd'=>$password
        ];
        $fa=true;
    }
}
if($fa){
    echo '登入成功<a href="userzhongxin.php">进入用户页面<a/>';
}else{
    echo'登入失败';
}


//echo gettype($username);
//echo $username."  ".$password;
//try {
//
//    $arr = connTools::select('select RealName from bankcard b join accountinfo a on a.AccountId = b.AccountId where cardno ='.$username.' and CardPwd = '.$password.';');
//    if(count($arr)<=0){
//        echo "账号和密码出错";
//    }else{
//        echo "登录成功<a href='userzhongxin.php'>欢迎进入用户中心<a/>";
//
//    }
//
//} catch (Throwable $e) {
//    echo $e->getMessage();
//}

